//
//  SettingViewController.m
//  FreightAssistant
//
//  Created by leo on 15/11/14.
//  Copyright © 2015年 leo. All rights reserved.
//

#import "SettingViewController.h"

#import "LogisticsListViewController.h"

static NSString *SettingTableViewIdentifier = @"SettingTableViewIdentifier";

@interface SettingViewController () {
    
    NSArray *_settingTitleArray;
}

@end

@implementation SettingViewController

- (void)loadView {
    [super loadView];
    
    UIView *tableHeaderView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, CGRectGetWidth(self.tableView.bounds), 120)];
    {
        UIView *contentView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, CGRectGetWidth(tableHeaderView.bounds), CGRectGetHeight(tableHeaderView.bounds))];
        contentView.backgroundColor = [UIColor whiteColor];
        contentView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
        [tableHeaderView addSubview: contentView];
        
        UIImageView* iconImageView = [[UIImageView alloc] initWithFrame: CGRectMake((CGRectGetWidth(contentView.bounds) - 60)/2, 15, 60, 60)];
        iconImageView.image = [UIImage imageNamed: @"AppIcon60x60@3x"];
        iconImageView.layer.cornerRadius = 5.0f;
        iconImageView.layer.masksToBounds = true;
        iconImageView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
        [contentView addSubview: iconImageView];
        
        UILabel *versionLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, CGRectGetMaxY(iconImageView.frame) + 7, CGRectGetWidth(contentView.bounds), 15)];
        versionLabel.textAlignment = NSTextAlignmentCenter;
        versionLabel.backgroundColor = [UIColor clearColor];
        versionLabel.font = [UIFont systemFontOfSize: 13];
        versionLabel.textColor = [UIColor colorWithHexString: @"b2b2b2"];
        versionLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
        versionLabel.text = [NSString stringWithFormat: @"当前版本V%@",[AppUtils getProjectVersion]];
        [contentView addSubview: versionLabel];
    }
    tableHeaderView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    self.tableView.tableHeaderView = tableHeaderView;
    
    [self.tableView registerClass: [UITableViewCell class] forCellReuseIdentifier: SettingTableViewIdentifier];
    
    self.tableView.tableFooterView = [UIView new];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationItem.title = @"系统设置";
    _settingTitleArray = @[@"物流商管理"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _settingTitleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: SettingTableViewIdentifier forIndexPath: indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.textLabel.text = _settingTitleArray[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSInteger row = indexPath.row;
    
    if (row == 0) {
        
        LogisticsListViewController *viewController = [LogisticsListViewController viewControllerFromStoryboard];
        [self.navigationController pushViewController: viewController animated: true];
    }
}


@end
